﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Start : System.Web.UI.Page
{
    private Game game;

    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
        {
            connection.Open();
            SqlCommand command = new SqlCommand(null, connection);

            // Insert into Game
            command.CommandText =
                "INSERT INTO Game (GameName) " +
                "VALUES (@name)";
            SqlParameter nameParam = new SqlParameter("@name", SqlDbType.Text, 100);
            nameParam.Value = "Game1";
            command.Parameters.Add(nameParam);

            // Call Prepare after setting the Commandtext and Parameters.
            command.Prepare();
            command.ExecuteNonQuery();

            //Insert into GamePlayers
            //command.CommandText =
            //   "INSERT INTO GamePlayers (GameID, PlayerID) " +
            //   "VALUES (@GameID, @PlayerID)";
            //SqlParameter gameId = new SqlParameter("@GameID", SqlDbType.Int);
            //SqlParameter playerId = new SqlParameter("@PlayerID", SqlDbType.UniqueIdentifier);
            //gameId.Value = 1;
            //playerId.Value = User.Identity.ID
            //command.Parameters.Add(nameParam);

            // Call Prepare after setting the Commandtext and Parameters.
            //command.Prepare();
            //command.ExecuteNonQuery();
        }

        //Player joined to listbox
        ListBox2.Items.Add(User.Identity.Name.ToString() + " joined the game."); 

        //When 3 players
        game = new Game(User.Identity.Name.ToString(), new List<string> { "Joe", "Bob" });
        UpdateForm();
    }

    public void UpdateForm()
    {
        ListBox1.Items.Clear();
        foreach (Card card in game.GetPlayerCardNames())
            ListBox1.Items.Add(card.Rank + " of " + card.Suit);
    
    }
}